import {
	defineStore
} from "pinia"
import {
	Category,
	GetHistory,
	Delete
} from "../api/modules/history"
// 定义pinia仓库
export const ShopStore = defineStore('ShopStore', {
	state: () => ({
		// 历史记录列表
		shopList: [],
		show: true,
		isCheck: false,
		skuList: { Videoid: [], uid: uni.getStorageSync('token') ? uni.getStorageSync('token').rows2[0].uid : 1}
	}),
	actions: {
		// 获取历史记录列表
		async updateList() {
			this.shopList = []
			const {
				message
			} = await Category(this.skuList.uid)
			message.forEach(async item => {
				const {
					message
				} = await GetHistory(item.Videoid)
				this.shopList.push(message)
			})
		},
		// 删除历史记录
		async DeleteGoods() {
			await Delete(this.skuList)
			this.updateList()
			console.log(this.skuList)
		}
	},
	getters: {
		// 是否全选
		isCheckAll: state => state.shopList.filter(item => item[0].ace).length === state.shopList.length,
	}

})
